package cn.xinyangtong.sso.service.impl;

import cn.xinyangtong.common.util.ConstantsUtil;
import cn.xinyangtong.sso.dao.JedisClient;
import cn.xinyangtong.sso.service.SessionProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

/**
 * Created by fengbo on 2017/8/2.
 */
@Service("sessionProvider")
public class SessionProviderImpl implements SessionProvider {

    @Autowired
    private JedisClient jedisClient;

    @Override
    public void setAttribute(String name, String value) {
        name = ConstantsUtil.USER_NAME + ":" + name;
        jedisClient.set(name, value);
        //时间
        jedisClient.expire(name, 30*60);
    }

    @Override
    public String getAttribute(String name) {
        name = ConstantsUtil.USER_NAME + ":" + name;
        String value = jedisClient.get(name);
        if (value != null) {
            jedisClient.expire(name, 30*60);
        }
        return value;
    }
}
